package phoneinfo;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.apache.hadoop.io.WritableComparable;

//对两列数字进行二次排序
public class SortNum implements WritableComparable<SortNum> {
	private int frist;
	private int second;

	public int getFrist() {
		return frist;
	}

	public void setFrist(int frist) {
		this.frist = frist;
	}

	public int getSecond() {
		return second;
	}

	public void setSecond(int second) {
		this.second = second;
	}

	public SortNum(int frist, int second) {
		super();
		this.frist = frist;
		this.second = second;
	}

	public SortNum() {

	}

	@Override
	public String toString() {
		return frist + "\t" + second;
	}


	@Override
	public void readFields(DataInput in) throws IOException {
		// TODO Auto-generated method stub
		this.frist = in.readInt();
		this.second = in.readInt();
	}
	@Override
	public void write(DataOutput out) throws IOException {
		// TODO Auto-generated method stub
		out.writeInt(frist);
		out.writeInt(second);
	}

	@Override
	// 通过重写该方法，从而改变shuffle阶段的对于key的默认排序规则
	public int compareTo(SortNum o) {
		// 首先判断第一列数字是否相等
		// 如果第一列相等,再判断第二列
		int result = this.frist - o.frist;
		if (result != 0) {
			return result;
		} else {
			return (o.second - this.second);
		}
	}

}
